# Create your views here.
import json

import requests
from django.views import View
from django.shortcuts import render
from apps.Mv.models import Mv_Detail
from apps.SongList.models import SongList
from apps.users.models import User
from utils.index_top import new_song, surge_song_top, hot_song_top, new_song_top, korea_song_top, EUROPE_song_top


class MainView(View):
    """主页"""
    def get(self, request):
        songlist_recommend = SongList.objects.filter(song_list_category=0)
        # 流行音乐歌单
        songlist_fashion = SongList.objects.filter(song_list_category=1)
        # 学习工作歌单
        songlist_student = SongList.objects.filter(song_list_category=2)
        # 网络歌曲歌单
        songlist_net = SongList.objects.filter(song_list_category=3)
        # 官方歌单
        songlist_official = SongList.objects.filter(song_list_category=4)
        # 浪漫歌单
        songlist_romance = SongList.objects.filter(song_list_category=5)
        # 获取最新歌曲
        new_song_list = new_song(self)
        # 获取飙升排行榜
        surge_top_list = surge_song_top(self)
        # 获取热歌榜排行
        hot_top_list = hot_song_top(self)
        # 获取新歌榜排行
        new_top_list = new_song_top(self)
        # 韩国排行榜
        Korea_top_list = korea_song_top(self)
        # 欧美排行榜
        EUROPE_top_list = EUROPE_song_top(self)
        # 获取精选mv
        Mv_choiceness = Mv_Detail.objects.filter(mv_category=0)
        # 获取内地MV
        Mv_hinterland = Mv_Detail.objects.filter(mv_category=1)
        # 获取欧美MV
        Mv_Europe = Mv_Detail.objects.filter(mv_category=2)

        context = {
            'songlist_recommend': songlist_recommend,
            'songlist_fashion': songlist_fashion,
            'songlist_student': songlist_student,
            'songlist_net': songlist_net,
            'songlist_official': songlist_official,
            'songlist_romance': songlist_romance,

            'surge_top_list': surge_top_list,
            'EUROPE_top_list': EUROPE_top_list,
            'Korea_top_list': Korea_top_list,
            'hot_top_list': hot_top_list,
            'new_top_list':new_top_list,
            'new_song_list': new_song_list,
            'Mv_choiceness': Mv_choiceness,
            'Mv_hinterland': Mv_hinterland,
            'Mv_Europe': Mv_Europe,

        }

        return render(request, 'main.html', context)


class IndexView(View):
    """顶页"""
    def get(self, request):
        username = request.session.get('username')
        user_id = request.session.get('user_id')
        try:
            users = User.objects.filter(id=user_id)
            user_img = ''
            for x in users:
                user_img = x.user_img
            context = {
                'user_id': user_id,
                'user_pic': user_img,
                'username': username
            }
        except Exception as e:
            context = {
                'user_id': '',
                'user_pic': '',
                'username': username
            }

        return render(request, "index.html", context)


class FooterView(View):
    """页脚"""
    def get(self, request):
        return render(request, "footer.html")


class Vip_View(View):
    """vip页面"""
    def get(self, request):
        return render(request, "Vip.html")



